package com.uduemc.biso.node.web.api.service.fegin.impl;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.uduemc.biso.core.utils.RestResult;
import com.uduemc.biso.node.core.entities.SContainerForm;
import com.uduemc.biso.node.core.feign.SContainerFormFeign;
import com.uduemc.biso.node.core.utils.RestResultUtil;
import com.uduemc.biso.node.web.api.service.fegin.SContainerFormService;

@Service
public class SContainerFormServiceImpl implements SContainerFormService {

	@Resource
	private SContainerFormFeign sContainerFormFeign;

	@Override
	public SContainerForm insert(SContainerForm sContainerForm) throws IOException {
		RestResult restResult = sContainerFormFeign.insert(sContainerForm);
		return RestResultUtil.data(restResult, SContainerForm.class);
	}

	@Override
	public SContainerForm findContainerFormmainbox(long hostId, long formId) throws IOException {
		RestResult restResult = sContainerFormFeign.findContainerFormmainboxByHostFormId(hostId, formId);
		return RestResultUtil.data(restResult, SContainerForm.class);
	}

	@Override
	public SContainerForm update(SContainerForm sContainerForm) throws IOException {
		RestResult restResult = sContainerFormFeign.updateById(sContainerForm);
		return RestResultUtil.data(restResult, SContainerForm.class);
	}

	@Override
	public SContainerForm findContainerFormmainbox(long id, long hostId, long formId) throws IOException {
		RestResult restResult = sContainerFormFeign.findOne(id);
		SContainerForm data = RestResultUtil.data(restResult, SContainerForm.class);
		if(data != null && data.getHostId() != null && data.getFormId() != null) {
			if(data.getHostId().longValue() == hostId && data.getFormId().longValue() == formId) {
				return data;
			}
		}
		return null;
	}
}
